package operate;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 10
 * Time: 20:31
 */
public class BorrowOperate implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入你要借阅的图书的名字");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();
        int currentNums = bookList.getBooknumbers();
        for (int i = 0; i < currentNums; i++) {
            if(bookList.getBook(i).getName().equals(bookName)) {
                if((bookList.getBook(i).getBorrow()) != true) {
                    bookList.getBook(i).setBorrow(true);
                    System.out.println("借阅图书成功");
                }else {
                    System.out.println("这本书已被借走");
                }
                return;
            }
        }
        System.out.println("没有你要借阅的图书");
    }
}
